import java.util.Arrays;

public class Mystack implements IStack{
    int[] elem;
private final int chushi=10;
    public Mystack(int[] elem) {
        this.elem = new int[chushi];
    }
    int usesize = 0;

    @Override
    public int push(int e) {
        if(full()){
            elem= Arrays.copyOf(elem,elem.length*2);
        }
        elem[usesize]=e;
         usesize++;
        return e;
    }
    @Override
    public boolean full(){
       if(usesize == elem.length){
           return true;
       }
       else {
           return false;
       }
    }

    @Override
    public int pop() {
        if(full()){
throw new EmpyExcetion("栈空了");
        }
        int old = elem[usesize-1];
        usesize--;
        return old;
    }

    @Override
    public int peek() {
       if(full()){
           throw new EmpyExcetion("栈空了");
       }
       return elem[usesize-1];
    }

    @Override
    public int size() {
        return 0;
    }

    @Override
    public boolean empty() {
        return usesize==0;
    }
    public class EmpyExcetion extends RuntimeException{
        public EmpyExcetion(String a) {
            super(a);
        }
    }

}
